package com.yuncheng.spcyApi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.alog.utils.StringEmptyUtils;
import com.yuncheng.spcyApi.constant.common.SpcyCommonConstant;
import com.yuncheng.spcyApi.entity.SpcyUserBgsq;
import com.yuncheng.spcyApi.mapper.SpcyUserBgsqMapper;
import com.yuncheng.spcyApi.service.ISpcyUserBgsqService;
import com.yuncheng.spcyApi.utils.GetCurrentUserUtils;
import com.yuncheng.spcyApi.utils.OrderItemUtils;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.yuncheng.common.base.service.impl.BaseServiceImpl;

import java.util.List;

/**
 * @Description: 审评查验-用户信息变更申请
 * @Author: yuncheng
 * @Date: 2023-11-11
 * @Version: V1.0
 */
@Service
public class SpcyUserBgsqServiceImpl extends BaseServiceImpl<SpcyUserBgsqMapper, SpcyUserBgsq> implements ISpcyUserBgsqService {

    @Override
    public List<SpcyUserBgsq> selectMyGzdwBgsq(String fshzt) {
        return list(new LambdaQueryWrapper<SpcyUserBgsq>()
                .eq(SpcyUserBgsq::getFuserid, GetCurrentUserUtils.getCurrentUserId())
                .eq(SpcyUserBgsq::getFbglx, SpcyCommonConstant.BGSQ_BGLX_GZDW)
                .eq(SpcyUserBgsq::getFshzt, fshzt));
    }

    @Override
    public List<SpcyUserBgsq> selectMyGzdwBgsqInWsh(String userid) {
        return list(new LambdaQueryWrapper<SpcyUserBgsq>()
                .eq(SpcyUserBgsq::getFuserid, userid)
                .eq(SpcyUserBgsq::getFbglx, SpcyCommonConstant.BGSQ_BGLX_GZDW)
                .ne(SpcyUserBgsq::getFshzt, SpcyCommonConstant.BGSQ_SHZT_YSH));
    }

    @Override
    public List<SpcyUserBgsq> selectMyLsbgdwList() {
        return list(new LambdaQueryWrapper<SpcyUserBgsq>()
                .eq(SpcyUserBgsq::getFuserid, GetCurrentUserUtils.getCurrentUserId())
                .eq(SpcyUserBgsq::getFbglx, SpcyCommonConstant.BGSQ_BGLX_GZDW)
                .orderByDesc(SpcyUserBgsq::getFfqsj));
    }

    @Override
    public Page<SpcyUserBgsq> selectMyLsbgdwPageList(String gjz,PageVo pageVo, OrderItemVo orderItemVo) {
        Page<SpcyUserBgsq> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        LambdaQueryWrapper<SpcyUserBgsq> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(SpcyUserBgsq::getFuserid, GetCurrentUserUtils.getCurrentUserId());
        queryWrapper.eq(SpcyUserBgsq::getFbglx, SpcyCommonConstant.BGSQ_BGLX_GZDW);
        queryWrapper.ne(SpcyUserBgsq::getFshzt, SpcyCommonConstant.BGSQ_SHZT_ZC);

        if (StringUtils.isNotBlank(gjz)){
            queryWrapper
                    .and(f->f.like(SpcyUserBgsq::getRealname, gjz)
                            .or()
                            .like(SpcyUserBgsq::getFbgqxx, gjz)
                            .or()
                            .like(SpcyUserBgsq::getFbghxx, gjz)
                            .or()
                            .like(SpcyUserBgsq::getFsftybg, gjz)
                            .or()
                            .like(SpcyUserBgsq::getFshzt, gjz)
                    );
        }

        if (StringEmptyUtils.isBlank(orderItemVo.getOrderItem())) {
            queryWrapper.orderByDesc(SpcyUserBgsq::getFfqsj);
        }else {
            OrderItemUtils.setOrderItem(queryWrapper, orderItemVo);
        }
        return page(page, queryWrapper);
    }
}
